const VIDEOS = [
  { id: 1, src: '', title: '', cameraId: null },
  { id: 2, src: '', title: '', cameraId: null },
  { id: 3, src: '', title: '', cameraId: null },
  { id: 4, src: '', title: '', cameraId: null },
  { id: 5, src: '', title: '', cameraId: null },
  { id: 6, src: '', title: '', cameraId: null },
];

const VIDEO_STREAMS = VIDEOS.map((stream) => {
  let src;
  let cameraId;
  const channels = JSON.parse(localStorage.getItem('channels') || '{}');
  switch (stream.id) {
    case 1:
      src = channels.channelOne;
      cameraId = channels.cameraOne;
      break;
    case 2:
      src = channels.channelTwo;
      cameraId = channels.cameraTwo;
      break;
    case 3:
      src = channels.channelThree;
      cameraId = channels.cameraThree;
      break;
    case 4:
      src = channels.channelFour;
      cameraId = channels.cameraFour;
      break;
    case 5:
      src = channels.channelFive;
      cameraId = channels.cameraFive;
      break;
    case 6:
      src = channels.channelSix;
      cameraId = channels.cameraSix;
      break;
    default:
      src = stream.src; // 如果没有匹配的 id，使用默认的 src
      cameraId = stream.cameraId;
  }
  return {
    ...stream,
    src,
    cameraId,
  };
}).filter((stream) => stream.src);

const VIDEO_TITLES = VIDEOS.map((item) => {
  const channels = JSON.parse(localStorage.getItem('channels') || '{}');
  let title;
  switch (item.id) {
    case 1:
      title = channels.channelOne ? item.title : undefined;
      break;
    case 2:
      title = channels.channelTwo ? item.title : undefined;
      break;
    case 3:
      title = channels.channelThree ? item.title : undefined;
      break;
    case 4:
      title = channels.channelFour ? item.title : undefined;
      break;
    case 5:
      title = channels.channelFive ? item.title : undefined;
      break;
    case 6:
      title = channels.channelSix ? item.title : undefined;
      break;
    default:
      title = undefined;
  }
  return title;
}).filter((i) => i !== undefined);

const VIDEO_STATUS = {
  loading: 'loading',
  success: 'success',
  error: 'error',
};

export { VIDEO_STATUS, VIDEO_STREAMS, VIDEO_TITLES };
